package com.universe.objects;

import com.universe.utils.Vector;

public class Body {
	
	private static final double G = 6.6738480e-11;
	
	double mass;
	Vector position;
	Vector velocity;
	Vector acceleration;
	
	public Body(double mass){
		this.mass = mass;
		this.position = new Vector(0,0);
		this.velocity = new Vector(0,0);
		this.acceleration = new Vector(0,0);
	}
	
	public Body(double mass, Vector position){
		this.mass = mass;
		this.position = position;
		this.velocity = new Vector(0,0);
		this.acceleration = new Vector(0,0);
	}
	
	public Body(double mass, Vector position, Vector velocity){
		this.mass = mass;
		this.position = position;
		this.velocity = velocity;
		this.acceleration = new Vector(0,0);
	}

	public double getMass() {
		return mass;
	}

	public Vector getPosition() {
		return position;
	}

	public Vector getVelocity() {
		return velocity;
	}

	public Vector getAcceleration() {
		return acceleration;
	}
	
	public void addBodyInfluence(Body b){
		Vector R = b.getPosition().minus(this.getPosition());
		this.acceleration = this.acceleration.plus(R.times((b.getMass() * G) / Math.pow(R.magnitude(), 3)));
	}
	
	public void move(double dT){
		velocity = velocity.plus(acceleration.times(dT));
		position = position.plus(velocity.times(dT));
		acceleration = new Vector(0, 0);
	}
}
